package com.yimi.appstore.adapter;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.yimi.appstore.R;
import com.yimi.appstore.activity.SpecialDetailActivity;

 
/**
 * 专题推荐适配器 
 * 应用，音乐，视频，小说公用
 * @author Tank
 *
 */
public class SpecialAdapter extends MyAdapter {

	public SpecialAdapter(Context context, List<HashMap<String, Object>> listData) {
		super(context, listData);
	}

	class ViewHolder {
		ImageView ivIcon;
		TextView tvTitle, tvDes;
		View view;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final HashMap<String, Object> item = listData.get(position);
		View v = showLoadingItem(item);
		if (v != null) {
			return v;
		}
		v = convertView;
		ViewHolder vh = null;
		if (v == null || v.getTag() == null) {
			v = lInflater.inflate(R.layout.listview_recommend_item, null);
			vh = new ViewHolder();
			vh.ivIcon = (ImageView) v.findViewById(R.id.app_cover);
			vh.tvTitle = (TextView) v.findViewById(R.id.app_title);
			vh.tvDes = (TextView) v.findViewById(R.id.app_info);
			vh.view = v.findViewById(R.id.recommend_layout);
			v.setTag(vh);
		} else {
			vh = (ViewHolder) v.getTag();
		}
		/*
		 * if (item.containsKey(ICON)) { vh.ivIcon.setImageBitmap((Bitmap)
		 * item.get(ICON)); } else {
		 * vh.ivIcon.setImageResource(R.drawable.app_deafault); } if
		 * (item.containsKey(NAME)) {
		 * vh.tvName.setText(item.get(NAME).toString()); } if
		 * (item.containsKey(RECOMMEND_EXPONENT)) {
		 * vh.rbStars.setRating(((Integer) (item.get(RECOMMEND_EXPONENT)) / 2
		 * )); }
		 */
 
		vh.view.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Toast.makeText(context, "position:" + position,
						Toast.LENGTH_SHORT).show();
				SpecialDetailActivity.lanuchActiviy(context, "");
			}

		});
		return v;
	}

	/**
	 * 下载app
	 * 
	 * @param context
	 * @param resourceId
	 * @param url
	 * @param fileName
	 * @param iconName
	 */
	public void downloadApp(Context context, String resourceId, String url,
			String fileName, String iconName) {/*
												 * DownloadManager
												 * downloadManager =
												 * DownloadManager
												 * .getInstance(context);
												 * downloadManager
												 * .addTask(resourceId, url, "",
												 * 1, fileName, iconName);
												 * Toast.makeText(context,
												 * "开始下载" + fileName + "...",
												 * Toast.LENGTH_SHORT) .show();
												 */
	}
}
